package com.jrx.anytxn.transaction.timer.job.queryPaymentStatus.step;

import com.jrx.anytxn.transaction.entity.TlPaymentLog;
import com.jrx.anytxn.transaction.mapper.ext.ExtTlPaymentLogMapper;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemWriter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 还款查询writer
 */
@Service
public class QueryPaymentStatusWriter implements ItemWriter<TlPaymentLog> {

    private static final Logger logger = LoggerFactory.getLogger(QueryPaymentStatusWriter.class);

    @Resource
    private ExtTlPaymentLogMapper extTlPaymentLogMapper;

    @Override
    public void write(List items) {
        List<TlPaymentLog> updateLogList = new ArrayList<>();
        for (Object item : items) {
            TlPaymentLog updateLog = (TlPaymentLog) item;
            updateLogList.add(updateLog);
        }

        if (CollectionUtils.isNotEmpty(updateLogList)) {
            extTlPaymentLogMapper.batchUpdateLogForBatch(updateLogList);
        }

    }
}
